<?php
/**
 * @author baby&star
 *
 *
 */
class ShopbrandController extends Controller{
	//TODO - Insert your code here
	function actionIndex(){
		$page = isset($_GET["page"])&&$_GET["page"]>0?$_GET["page"]:1;
		$shopBrand = new Shop_brand();
		$data = $shopBrand->getList(null,"id desc",$page,$this->createUrl("shopbrand/index"));
		
		$this->render("index",array("data"=>$data));
		
	}
	/**
	 * 新增
	 * Enter description here ...
	 */
	function actionAdd(){
		if($_POST){
			
			$shopBrand = new Shop_brand();
			
			$arr = array(
				'name'           => $_POST['name'],
				'webSite'        => $_POST['webSite'],
				'setPage'        => $_POST['setPage'],
				'status'         => $_POST['status'],
				'type'           => $_POST['type'],
				'blockDelimiter' => $_POST['blockDelimiter'],
				'pricePattern'   => $_POST['pricePattern'],
				'titlePattern'   => $_POST['titlePattern'],
				'imgPattern'     => $_POST['imgPattern'],
				'hrefPattern'    => $_POST['hrefPattern'],
				'pagePattern'    => $_POST['pagePattern'],
				'intro'          => $_POST['intro']
			);
			
			if($_POST["type"] == 3){
				unset($arr["pricePattern"],$arr["titlePattern"],$arr["imgPattern"],$arr["hrefPattern"],$arr["pagePattern"]);
			}
			
			if(empty($arr['name'])){
				Common::jsalerturl("请填写名称！");
				exit;
			}
			
			if(empty($arr['webSite'])){
				Common::jsalerturl("请填写网站地址！");
				exit;
			}
			
			if(empty($arr['blockDelimiter'])||empty($arr['pricePattern'])||empty($arr['titlePattern'])||empty($arr['imgPattern'])||empty($arr['hrefPattern'])){
				if($arr['status'] == 0 && $_POST["type"]!=3){
					Common::jsalerturl("正则没有填写完整 ，系统不能完成抓取！");
					exit;
				}
			}
			
			if($shopBrand->insertData($arr)){
				Common::jsalerturl("提交成功！");
			}else{
				Common::jsalerturl("提交失败！");
			}
			exit;
			
		}
		$this->render("add");
	}
	/**
	 * 修改
	 * Enter description here ...
	 */
	function actionModify(){
		$shopbrand = new Shop_brand();
		if($_POST){
			$id = $_POST["id"];
			if(!is_numeric($id)){
				Common::jsalerturl("非法操作！",$this->createUrl("shopbrand/index"));
				exit;
			}
			$arr = array(
				'name'           => $_POST['name'],
				'webSite'        => $_POST['webSite'],
				'type'           => $_POST['type'],
				'setPage'        => $_POST['setPage'],
				'status'         => $_POST['status'],
				'blockDelimiter' => $_POST['blockDelimiter'],
				'pricePattern'   => $_POST['pricePattern'],
				'titlePattern'   => $_POST['titlePattern'],
				'imgPattern'     => $_POST['imgPattern'],
				'hrefPattern'    => $_POST['hrefPattern'],
				'pagePattern'    => $_POST['pagePattern'],
				'intro'          => $_POST['intro']
			);
			if($_POST["type"] == 3){
				unset($arr["pricePattern"],$arr["titlePattern"],$arr["imgPattern"],$arr["hrefPattern"],$arr["pagePattern"]);
			}
			$shopbrand->updateData($arr, "`id` = $id");
			Common::jsalerturl("修改成功！",$this->createUrl("shopbrand/index"));
		
			exit;
		}
		$id = $_GET["id"];
		if(empty($id)){
			Common::jsalerturl("非法操作！");
			exit;
		}
		
		
		
		$rs = $shopbrand->getById("`id` = $id");
		
		$this->render("modify",array("rs"=>$rs));
	}
	/**
	 * 删除
	 */
	function actionDelete(){
		
	}
}


?>